<template>
  <div class="parkingmng-container">
    <div class="page-title">
      <svg class="icon icon-zhibanguanli" aria-hidden="true">
        <use xlink:href="#icon-zhibanguanli"/>
      </svg>
      <span>停车场管理</span>
      <pagego :path="parkingmngPath"/>
    </div>
    <div class="main-content">
      <div class="tool-bar">
        <span style="font-size: 14px;">停车场</span>
        <el-select v-model="name" placeholder="请选择" size="small">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"/>
        </el-select>
        <div class="search-box">
          <span style="font-size: 14px;">负责人姓名</span>
          <el-input
            v-model="principalName"
            size="small"
            clearable/>
          <span style="font-size: 14px;">地点</span>
          <el-input
            v-model="place"
            size="small"
            clearable/>
          <el-button size="small" type="primary" icon="el-icon-search" @click="getListData">查询</el-button>
        </div>
      </div>
      <el-table
        :data="tableData"
        border
        stripe
        style="width: 100%">
        <!--<el-table-column
          type="selection"
          align="center"
          width="55"/>-->
        <el-table-column
          prop="id"
          label="序号"
          align="center"
          width="50"/>
        <el-table-column
          prop="name"
          label="名称"/>
        <el-table-column
          prop="place"
          label="地点"/>
        <el-table-column
          prop="principalName"
          label="负责人姓名"/>
        <el-table-column
          prop="principalContact"
          width="120"
          label="负责人联系方式"/>
        <el-table-column
          prop="parkingNum"
          width="120"
          label="停车位个数"/>
        <el-table-column
          prop="longitudeAndLatitude"
          width="120"
          label="经纬度"/>
        <el-table-column
          prop="manufacturer"
          label="厂商"/>
        <el-table-column
          prop="afterSalesInfo"
          width="120"
          label="售后人员信息"/>
        <el-table-column
          prop="address"
          width="190"
          align="center"
          label="执行操作">
          <template slot-scope="scope">
            <el-button size="small" icon="el-icon-edit" @click="handleClick(scope.row)">编辑</el-button>
            <el-button size="small" type="danger" icon="el-icon-delete" @click="handleClickDelete(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="tool-bar">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          :total="totalNum"
          layout=" prev, pager, next, sizes, total "
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"/>
      </div>
    </div>
    <el-dialog :visible.sync="dialogFormVisible" title="编辑信息" width="30%">
      <el-form :model="form">
        <el-form-item :label-width="formLabelWidth" label="名称">
          <el-input v-model="form.name" size="small"/>
        </el-form-item>
        <el-form-item :label-width="formLabelWidth" label="地点">
          <el-input v-model="form.place" size="small"/>
        </el-form-item>
        <el-form-item :label-width="formLabelWidth" label="负责人姓名">
          <el-input v-model="form.principalName" size="small"/>
        </el-form-item>
        <el-form-item :label-width="formLabelWidth" label="负责人联系方式">
          <el-input v-model="form.principalContact" size="small"/>
        </el-form-item>
        <el-form-item :label-width="formLabelWidth" label="停车位个数">
          <el-input v-model="form.parkingNum" size="small"/>
        </el-form-item>
        <!--<el-form-item :label-width="formLabelWidth" label="停车场经纬度">
          <el-input v-model="form.longitudeAndLatitude" size="small" readonly="true"/>
          <el-button size="small" icon="el-icon-edit" @click="chooseLongitudeAndLatitude(scope.row)">选择</el-button>
        </el-form-item>-->
        <el-form-item :label-width="formLabelWidth" label="厂商">
          <el-input v-model="form.manufacturer" size="small"/>
        </el-form-item>
        <el-form-item :label-width="formLabelWidth" label="售后人员信息">
          <el-input v-model="form.afterSalesInfo" size="small"/>
        </el-form-item>
        <el-form-item :label-width="formLabelWidth" label="最近派出所名称">
          <el-input v-model="form.nearestPoliceName" size="small"/>
        </el-form-item>
        <el-form-item :label-width="formLabelWidth" label="最近派出所联系方式">
          <el-input v-model="form.nearestPoliceContact" size="small"/>
        </el-form-item>
        <el-form-item :label-width="formLabelWidth" label="最近消防部门名称">
          <el-input v-model="form.nearestFireAgentName" size="small"/>
        </el-form-item>
        <el-form-item :label-width="formLabelWidth" label="最近消防部门联系方式">
          <el-input v-model="form.nearestFireAgentContact" size="small"/>
        </el-form-item>
        <el-form-item :label-width="formLabelWidth" label="最近医院名称">
          <el-input v-model="form.nearestHospitalName" size="small"/>
        </el-form-item>
        <el-form-item :label-width="formLabelWidth" label="最近医院联系方式">
          <el-input v-model="form.nearestHospitalContact" size="small"/>
        </el-form-item>
        <el-form-item :label-width="formLabelWidth" label="描述">
          <el-input v-model="form.description" size="small"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" size="small" @click="updateData">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { Message } from 'element-ui'
import Pagego from '@/components/pageGoBtn/index'
import { getList, update, deleteRecord } from '@/api/parkingmng.js'

export default {
  name: 'ParkingMng',
  components: {
    Pagego
  },
  data () {
    return {
      name: '', // 停车场
      principalName: '', // 负责人姓名
      place: '', // 地点
      totalNum: 0, // 数据总数
      pageSize: 100,
      radio: '1',
      value: 'all',
      options: [{
        value: 'all',
        label: '全部'
      }, {
        value: '2',
        label: '停车场1'
      }, {
        value: '3',
        label: '停车场2'
      }, {
        value: '4',
        label: '停车场4'
      }, {
        value: '5',
        label: '停车场5'
      }],
      parkingmngPath: '/example/parkingmng',
      dialogFormVisible: false,
      form: {
        id: '',
        name: '',
        place: '',
        principalName: '',
        principalContact: '',
        parkingNum: '',
        longitudeAndLatitude: '',
        manufacturer: '',
        afterSalesInfo: '',
        nearestPoliceName: '',
        nearestPoliceContact: '',
        nearestFireAgentName: '',
        nearestFireAgentContact: '',
        nearestHospitalName: '',
        nearestHospitalContact: '',
        description: ''
      },
      formLabelWidth: '160px',
      currentPage: 1,
      searchText: '',
      tableData: [] // 表格数据
    }
  },
  watch: {},
  mounted () {
    this.getListData()
  },
  methods: {
    // 选择经纬度
    chooseLongitudeAndLatitude (row) {

    },
    // 获取页面数据
    getListData () {
      const params = {
        name: this.name,
        principalName: this.principalName,
        place: this.place,
        pageNo: this.currentPage,
        pageSize: this.pageSize
      }
      getList(params)
        .then(res => {
          this.tableData = res.page.list
          this.totalNum = res.page.totalNum
        })
    },
    // 更新数据
    updateData () {
      const params = this.form
      update(params)
        .then(res => {
          this.dialogFormVisible = false
          Message.success(res.msg)
        })
    },
    handleClick (row) {
      console.log(row)
      this.dialogFormVisible = true
      this.form = row
    },
    // 删除数据
    handleClickDelete (row) {
      deleteRecord(row.id)
        .then(res => {
          Message.success(res.msg)
        })
    },
    submitData () {
      this.dialogFormVisible = false
      Message.success('编辑成功～')
    },
    handleSizeChange (val) {
      this.pageSize = val
      this.getListData()
    },
    handleCurrentChange (val) {
      this.currentPage = val
      this.getListData()
    }
  }
}
</script>

<style lang="stylus" scoped>
.parkingmng-container{
  margin: 15px;
  color: #828282;
  font-size: 16px;
  background-color: #fff;
  padding-top: 0px;
  .status-span{
    color: #fff;
    display: inline-block;
    padding: 0px 10px;
    font-size: 12px;
  }
  .color-span-1{
    background-color: #5cb85c;
  }
  .color-span-2{
    background-color: #5bc0de;
  }
  .color-span-3{
    background-color: #f0ad4e;
  }
  .color-span-4{
    background-color: #d9534f;
  }
  .el-input{
    display: inline-block;
  }
  .page-title{
    width:100%;
    height: 44px;
    line-height: 44px;
    border-bottom: 1px solid #e5e5e5;
    margin-bottom: 5px;
    padding: 0 15px;
    .icon{
      width: 22px;
      height: 22px;
      position: relative;
      top: 3px;
    }
  }
  .main-content{
    padding: 15px;
    padding-top: 0px;
    .tool-bar {
      padding: 10px 0px;
      position: relative;
      .search-box{
        position: absolute;
        right: 10px;
        top: 10px;
        .el-input{
          width: 120px;
        }
      }
    }
  }
}
</style>
